//
//  RegisterView.m
//  ShowMe
//
//  Created by 123 on 2018/8/22.
//  Copyright © 2018年 nkl. All rights reserved.
//

#import "RegisterView.h"
@interface RegisterView()
@property (weak, nonatomic) IBOutlet UITextField *pwdFirst;
@property (weak, nonatomic) IBOutlet UITextField *pwdSecond;
@property (weak, nonatomic) IBOutlet UITextField *verificationCode;
@property (weak, nonatomic) IBOutlet UITextField *phoneNumber;
@property (weak, nonatomic) IBOutlet UIButton *verButton;
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIImageView *headerIcon;
@property (weak, nonatomic) IBOutlet UIButton *backButton;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIButton *registBtn;

@end

@implementation RegisterView

-(void)awakeFromNib{
    [super awakeFromNib];
    //验证码按钮
    self.verButton.layer.cornerRadius = 5;
    //其他界面设置
    //背景view
    self.bgView.backgroundColor = [UIColor whiteColor];
    self.bgView.layer.cornerRadius = 10;
    self.bgView.layer.borderColor = CGColor(187, 187, 187, 1);
    self.bgView.layer.borderWidth = 1;
    self.bgView.layer.shadowColor = CGColor(170, 170, 170, 1);
    self.bgView.layer.shadowOpacity = 1;
    self.bgView.layer.shadowOffset = CGSizeMake(0, 0);
    self.bgView.layer.shadowRadius = 20;
    //注册按钮
    self.registBtn.layer.cornerRadius = 10;
    self.registBtn.layer.masksToBounds = YES;
    //头像
    self.headerIcon.layer.cornerRadius = __KNewSize(45);
    self.headerIcon.layer.masksToBounds = YES;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(__KNewSize(48));
        make.right.equalTo(self).offset(__KNewSize(-48));
        make.top.equalTo(self).offset(__KNewSize(112));
        make.bottom.equalTo(self).offset(__KNewSize(-107));
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(__KNewSize(43));
        make.centerX.equalTo(self);
    }];
    
    [self.headerIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView).offset(__KNewSize(40));
        make.centerX.equalTo(self.bgView);
        make.width.height.mas_equalTo(__KNewSize(90));
    }];
    [self.phoneNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView).offset(__KNewSize(36));
        make.right.equalTo(self.bgView).offset(__KNewSize(-35));
        make.top.equalTo(self.headerIcon.mas_bottom).offset(__KNewSize(30));
    }];
    [self.pwdFirst mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView).offset(__KNewSize(36));
        make.right.equalTo(self.bgView).offset(__KNewSize(-35));
        make.top.equalTo(self.phoneNumber.mas_bottom).offset(__KNewSize(30));
    }];
    [self.pwdSecond mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView).offset(__KNewSize(36));
        make.right.equalTo(self.bgView).offset(__KNewSize(-35));
        make.top.equalTo(self.pwdFirst.mas_bottom).offset(__KNewSize(30));
    }];
    [self.verButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.bgView).offset(__KNewSize(-35));
        make.top.equalTo(self.pwdSecond.mas_bottom).offset(__KNewSize(30));
        make.height.equalTo(self.pwdSecond.mas_height);
    }];
    [self.verificationCode mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView).offset(__KNewSize(36));
        make.right.equalTo(self.verButton.mas_left).offset(__KNewSize(-10));
        make.top.equalTo(self.pwdSecond.mas_bottom).offset(__KNewSize(30));
        make.height.equalTo(self.pwdSecond.mas_height);
    }];
    [self.registBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.verificationCode.mas_bottom).offset(__KNewSize(30));
        make.left.equalTo(self.bgView).offset(__KNewSize(36));
        make.right.equalTo(self.bgView).offset(__KNewSize(-36));
        make.bottom.equalTo(self.bgView).offset(__KNewSize(-10));
    }];
    
    [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
         make.top.equalTo(self.bgView.mas_bottom).offset(__KNewSize(50));
        make.bottom.equalTo(self).offset(__KNewSize(-27));
    }];
    
}


-(instancetype)loadLoginViewFromXib{
    return  [[NSBundle mainBundle] loadNibNamed:@"RegistView" owner:self options:nil].lastObject;
}

- (IBAction)sendMessageBtnClick:(id)sender {
    if ([self.delegate respondsToSelector:@selector(sendMessageBtnClick:phoneNumber:)]) {
        [self.delegate sendMessageBtnClick:sender phoneNumber:self.phoneNumber.text];
    }
}
- (IBAction)registBtnClickEvent:(id)sender {
    if ([self.delegate respondsToSelector:@selector(registCounter:password:password2:verCode:)]) {
        [self.delegate registCounter:self.phoneNumber.text password:self.pwdFirst.text password2:self.pwdSecond.text verCode:self.verificationCode.text];
    }
}

- (IBAction)backToLoginEevent:(id)sender {
    if ([self.delegate respondsToSelector:@selector(backToLoginViewClick)]) {
        [self.delegate backToLoginViewClick];
    }
}



- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self endEditing:YES];
}

@end
